<template>
  <div class="customer-list">
    <div class="page-header">
      <div class="left">
        <el-button type="primary" size="small" @click="handleAdd">新增</el-button>
        <el-button size="small">导入</el-button>
      </div>
      <div class="right">
        <el-input
          v-model="searchQuery"
          placeholder="搜索"
          prefix-icon="el-icon-search"
          size="small"
          style="width: 200px"
        />
        <el-button icon="el-icon-menu" circle size="small"></el-button>
      </div>
    </div>
    <el-table
      :data="customerList"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column type="index" label="序号" width="60"></el-table-column>
      <el-table-column prop="customerNo" label="客户编号" width="120"></el-table-column>
      <el-table-column prop="customerName" label="客户名称" width="120"></el-table-column>
      <el-table-column prop="companyName" label="公司名" width="180"></el-table-column>
      <el-table-column prop="customerType" label="客户类别" width="120"></el-table-column>
      <el-table-column prop="customerLevel" label="客户等级" width="120"></el-table-column>
      <el-table-column prop="industry" label="所属行业" width="120"></el-table-column>
      <el-table-column prop="region" label="所在地区" width="120"></el-table-column>
      <el-table-column prop="manager" label="客户经理" width="120"></el-table-column>
      <el-table-column prop="department" label="所在部门" width="120"></el-table-column>
      <el-table-column prop="contact" label="联系人" width="120"></el-table-column>
      <el-table-column prop="phone" label="联系电话" width="120"></el-table-column>
      <el-table-column prop="status" label="状态" width="80">
        <template slot-scope="scope">
          <span :style="{ color: scope.row.status === '是' ? '#67C23A' : '#F56C6C' }">
            {{ scope.row.status }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" size="small" style="color: #67C23A" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button type="text" size="small" style="color: #F56C6C" @click="handleDelete(scope.row)">删除</el-button>
          <el-button type="text" size="small" style="color: #409EFF" @click="handleView(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <span class="total-info"></span>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="pageSize"
        layout="sizes, prev, pager, next, jumper"
        :total="101">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CustomerList',
  data() {
    return {
      searchQuery: '',
      customerList: [],
      currentPage: 1,
      pageSize: 5,
      selectedRows: []
    }
  },
  methods: {
    handleSelectionChange(val) {
      this.selectedRows = val;
    },
    handleSizeChange(val) {
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    handleEdit(row) {
      console.log('编辑', row);
    },
    handleDelete(row) {
      console.log('删除', row);
    },
    handleView(row) {
      console.log('查看', row);
    },
    handleAdd() {
      this.$router.push('/customer/add-customer').catch(err => {
        if (err.name !== 'NavigationDuplicated') {
          throw err;
        }
      });
    }
  }
}
</script>

<style scoped>
.customer-list {
  padding: 20px;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.left {
  display: flex;
  gap: 10px;
}
.right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.total-info {
  margin-right: 15px;
  color: #606266;
  font-size: 13px;
}
.el-button--text {
  padding: 2px 4px;
}
/* 设置表格内容居中 */
.el-table >>> .el-table__cell {
  text-align: center;
}
/* 设置表头居中 */
.el-table >>> th {
  text-align: center !important;
}
/* 设置表格斑马纹 */
.el-table >>> .el-table__row:nth-child(even) {
  background-color: #FAFAFA;
}
</style> 